
/* e-attnam.p */

DEFINE VARIABLE hDoc AS HANDLE.
DEFINE VARIABLE hRoot AS HANDLE.
DEFINE VARIABLE good AS LOGICAL.

CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.

hDoc:LOAD("file","c:\qadguicli\cust.xml",FALSE).
/*
hDoc:LOAD("file","c:\sample\newcust.xml",FALSE).
*/
hDoc:GET-DOCUMENT-ELEMENT(hRoot).

RUN GetChildren(hRoot, 1).

DELETE OBJECT hDoc.
DELETE OBJECT hRoot.

PROCEDURE GetChildren:
    DEFINE INPUT PARAMETER hParent AS HANDLE.
    DEFINE INPUT PARAMETER level AS INTEGER.

    DEFINE VARIABLE i AS INTEGER.
    DEFINE VARIABLE j AS INTEGER.
    DEFINE VARIABLE hNoderef AS HANDLE.

    DEFINE VARIABLE entries AS CHARACTER .
    DEFINE VARIABLE aname AS CHARACTER .

    CREATE X-NODEREF hNoderef.

    REPEAT i = 1 TO hParent:NUM-CHILDREN WITH FRAME a DOWN :

        good = hParent:GET-CHILD(hNoderef,i).
        IF NOT good THEN LEAVE.

        entries = hNoderef:ATTRIBUTE-NAMES.

        IF hNoderef:NAME = "#TEXT" THEN 

          DISP hNoderef:TYPE hNoderef:SUBTYPE hNoderef:NAME hNoderef:LOCAL-NAME hNoderef:NODE-VALUE FORMAT "x(40)" . 


        REPEAT j = 1 TO NUM-ENTRIES(entries):
            aname = ENTRY(j, entries).
            DISP "attrname is " aname "value is " hNoderef:GET-ATTRIBUTE(aname).
        END.

        RUN GetChildren(hNoderef, (level + 1)).

    END.
    
    DELETE OBJECT hNoderef.

END PROCEDURE.
